package com.share.im.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.share.im.R;
import com.share.im.model.UserBean;

public class SearchUserAdapter extends BaseAdapter
{
	private Context context;
	private LayoutInflater mInflater;
	private List<UserBean> list;
	
	public SearchUserAdapter(Context context,List<UserBean> list){
		this.context = context;
		this.list = list;
		mInflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount()
	{
		return list.size();
	}

	@Override
	public Object getItem(int position)
	{
		return list.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		UserBean user = list.get(position);
		ViewHolderx holder = null;
		if (convertView == null)
		{
			convertView = mInflater.inflate(R.layout.search_user_item, null);
			holder = new ViewHolderx();
			holder.icon = (ImageView) convertView.findViewById(R.id.img_icon);
			holder.name = (TextView) convertView.findViewById(R.id.txt_name);
			holder.content = (TextView) convertView.findViewById(R.id.txt_content);
			convertView.setTag(holder);
		}
		else
		{
			holder = (ViewHolderx) convertView.getTag();
		}
		holder.icon.setBackgroundResource(R.drawable.h001);
		holder.name.setText(user.getName());
		StringBuilder sb = new StringBuilder();
		//sb.append(user.getSex());
		sb.append(user.getEmail());
		sb.append(" ");
		sb.append(user.getStatus()==1?"已是好友":"");
		holder.content.setText(sb.toString());
		holder.content.setTag(user);
		
		return convertView;
	}

	public class ViewHolderx
	{
		public ImageView icon;
		public TextView name;
		public TextView content;

	}

}
